package com.duying.gh.manager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.duying.gh.GhCommonManager;
import com.duying.gh.model.Category;
import com.duying.gh.model.CategoryUser;

public class CategoryUserManager extends GhCommonManager{
	
	public void deleteByCategoryId(Integer categoryId){
		String hql = "delete from CategoryUser cu where cu.category.id =:categoryId";
		Map map = new HashMap();
		map.put("categoryId", categoryId);
		this.baseDao.excuteByHql(hql, map);
	}
	
	
	public List getListByUserId(Integer userId){
		String hql = "from CategoryUser cu where cu.systemUser.id =:userId";
		Map map = new HashMap();
		map.put("userId", userId);
		return this.baseDao.getByHQL(hql, map);
	}
	
	
	public List getSelectTree(List listCategory){
		
		List listSelectTree = new ArrayList();
		
		Map VirtualMap = new HashMap();
		VirtualMap.put("pvalue","  ");
		VirtualMap.put("pkey",0);
		listSelectTree.add(VirtualMap);
		
		for(Object obj : listCategory){
			int depth = 1;
			CategoryUser cu = (CategoryUser)obj;
			Category c = cu.getCategory();
			Map map = new HashMap();
			map.put("pvalue",c.getCategory_name());
			map.put("pkey",c.getId());
			listSelectTree.add(map);
		}
		return listSelectTree;
	}
}
